package spring.data.jpa.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import spring.data.jpa.entity.Employee;
import spring.data.jpa.repository.CommonJpaRepository;

@Service
public class EmployeeService {

	@Resource(name = "employeeRepository")
	private CommonJpaRepository<Employee, Long> employeeRepository;

	@Transactional
	public void save(Employee entity) {
	    employeeRepository.save(entity);
	}
	
    public List<Employee> findAll() {
        return employeeRepository.findAll();
    }
    
    public List<Employee> findByParams(Employee employee) {
        String jpql = "select t from Employee t where t.name=?1";
        return employeeRepository.findAll(jpql, employee.getName());
    }
}
